extends Control

## 主要是售卖功能，装备拖到此处可以售卖

@onready var sell_panel: Panel = $Panel
@onready var sell_label: Label = $Label

const sell_price = {
	1: 50,
	2: 150,
	3: 300,
	4: 500
}

func _ready() -> void:
	# 初始化售卖面板为隐藏状态
	on_to_sell_end()
	EventBus.subscribe("to_sell_start", on_to_sell_start)
	EventBus.subscribe("to_sell_end", on_to_sell_end)

func _can_drop_data(_at_position: Vector2, _data: Variant) -> bool:
	return true

func _drop_data(_at_position: Vector2, _data: Variant) -> void:
	if _data is not MouseSlot:
		return
	var dict = _data.item_info_dict
	var level = dict["level"]
	var price = sell_price[level]
	## 获取售卖价格
	Utils.set_player_stats_value("gold", price)
	_data.clear_mouse_slot()

func on_to_sell_start(level):
	sell_label.text = "拖到此处卖出%s金币" % sell_price[level]
	self.visible = true
	sell_panel.visible = true
	sell_label.visible = true

func on_to_sell_end():
	self.visible = false
	sell_panel.visible = false
	sell_label.visible = false
